package com.sky.mapper;


import com.sky.entity.SetmealDish;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealDishMapper {

    /**
     * 根据套菜品id查询对应的套餐id
     * @param dishIds
     * @return
     */
    List<Long> getSetmealIdsByDishIds(List<Long> dishIds);

    /**
     * 批量保存套餐和菜品的关联关系
     * @param setmealDishes
     */
    void insertBatch(List<SetmealDish> setmealDishes);

    /**
     * 删除套餐和菜品的关联关系
     * @param setmealId
     */
    @Delete("delete from  setmeal_dish where setmeal_id = #{setmealId}")
    void deleteBySetmealId(Long setmealId);

    /**
     * 据id查询套餐和菜品的关联关系
     * @param setmealId
     * @return
     */
    @Select("select * from setmeal_dish where setmeal_id = #{setmealId}")
    List<SetmealDish> getBySetmealId(Long setmealId);

    /**
     * 根据菜品id删除套餐和菜品的关联关系
     * @param dishIdsToDelete 菜品的id集合
     * @param setmealId 套餐的id
     */
    @Delete("<script>" +
            "DELETE FROM setmeal_dish WHERE setmeal_id = #{setmealId} AND dish_id IN " +
            "<foreach collection='dishIdsToDelete' item='dishId' open='(' separator=',' close=')'>" +
            "#{dishId}" +
            "</foreach>" +
            "</script>")
    void deleteByDishIds(@Param("dishIdsToDelete") List<Long> dishIdsToDelete, @Param("setmealId") Long setmealId);
}
